include ../../Makefile.config

all: nspireio-src-extract nspireio-2.0 patches-init patches ../dist
	@becho "Building NspireIO library..."
	make -C nspireio-2.0/src
	@becho "Installing NspireIO library to the ndLua source tree..."
	make -C nspireio-2.0/src install DESTDIR=$(NDLUA_TOP)/extlibs/dist

../dist:
	@becho "Distribution directory doesn't exist. Creating it now."
	make -C .. dirprep

nspireio-src-extract:
	@becho "Extracting NspireIO source..."
	if [ -d nspireio-2.0 ]; then rm -rf nspireio-2.0; fi
	unzip nspireio2-fix.zip && touch nspireio-src-extract

# If we run this target, that means something made the nspireio-2.0
# source directory disappear! We need to fix that.
nspireio-2.0:
	@becho "Uh oh... the NspireIO source directory disappeared! Attempting to recover..."
	rm -f nspireio-src-extract
	make nspireio-src-extract
	@becho "Successfully recovered from missing NspireIO source directory."

patches-init:
	@becho "Patching NspireIO source..."
	@make -C patches

clean:
	@becho "Cleaning up NspireIO source tree..."
	make -C nspireio-2.0/src clean

distclean:
	@becho "Cleaning up all of NspireIO source tree..."
	make -i -C patches distclean
	rm -rf nspireio-2.0 nspireio-src-extract
